package com.wd.live.base

import android.os.Bundle
import android.service.voice.VoiceInteractionSession.ActivityId
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import java.lang.reflect.ParameterizedType

/**
 * 作者: 张智聪
 * 时间: 2024/10/15
Time:  15:44
 * 描述:
 */
abstract class BaseActivity <VM:ViewModel,D:ViewDataBinding>(private  val  layoutId:Int):AppCompatActivity(){
  lateinit var viewmodel:VM
  lateinit var binding:D
    override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      binding=DataBindingUtil.setContentView(this,layoutId)
      val type=javaClass.genericSuperclass as ParameterizedType
      val classVM=type.actualTypeArguments[0] as Class<VM>
      viewmodel= ViewModelProvider(this)[classVM]
      initViews()
      dataObserver()
    }
  abstract fun dataObserver()
  abstract fun initViews()
  override fun onDestroy() {
    super.onDestroy()
    if(binding!=null){
        binding.unbind()
    }
  }
}